GLvoid BuildFont(GLvoid)        // Build our font display list
{
	float	cx;				                	// Holds our X character coord
	float	cy;
        int loop;				                	// Holds our Y character coord

	base = glGenLists(256);                                         // Creating 256 display lists
	glBindTexture(GL_TEXTURE_2D, texture[font_tex].TexID);             	// Select our font texture
	for (loop = 0; loop < 256; loop++)		                // Loop through all 256 lists
	{
		cx = float(loop%16)/16.0f;	                	// X position of current character
		cy = float(loop/16)/16.0f;	                	// Y position of current character

		glNewList(base+loop,GL_COMPILE);	                // Start building a list
			glBegin(GL_QUADS);		                // Use a quad for each character
				glTexCoord2f(cx,1-cy-0.0625f);		// Texture coord (bottom left)
				glVertex2i(0,0);			// Vertex coord (Bottom left)
				glTexCoord2f(cx+0.0625f,1-cy-0.0625f);	// Texture coord (Bottom right)
				glVertex2i(16,0);			// Vertex coord (Bottom right)
				glTexCoord2f(cx+0.0625f,1-cy);		// Texture coord (Top right)
				glVertex2i(16,16);			// Vertex coord (Top right)
				glTexCoord2f(cx,1-cy);			// Texture coord (Top left)
				glVertex2i(0,16);			// Vertex coord (Top left)
			glEnd();					// Done building our quad (Character)
			glTranslated(10,0,0);				// Move to the right of the character
		glEndList();						// Done building the display list
	}								// Loop until all 256 are built
}

GLvoid KillFont(GLvoid)         // Delete the font
{
        glDeleteLists(base, 256);	// Delete all 256 characters
}

GLvoid glPrint(GLint x, GLint y, int set, const char *fmt, ...)	// Where the printing happens
{
        GLfloat mat_ambient[] = { 1.0, 1.0, 0.0, 1.0 };
        glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);

	char text[1024];                // Holds our string
	va_list ap;			// Pointer to list of arguments

	if (fmt == NULL)		// If there's no text
		return;			// Do nothing

	va_start(ap, fmt);		// Parses the string for variables
	    vsprintf(text, fmt, ap);	// And converts symbols to actual numbers
	va_end(ap);			// Results are stored in text

	if (set > 1)
	{
		set = 1;
	}
	glBindTexture(GL_TEXTURE_2D, texture[font_tex].TexID);	// Select our font texture
	glDisable(GL_DEPTH_TEST);			// Disables depth testing
        glEnable(GL_BLEND);			        // Enable blending
        glEnable(GL_TEXTURE_2D);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Type of blending to use
	glMatrixMode(GL_PROJECTION);			// Select the projection matrix
	glPushMatrix();					// Store the projection matrix
	glLoadIdentity();				// Reset the projection matrix
	glOrtho(0,640,0,480,-1,1);			// Set up an ortho screen
	glMatrixMode(GL_MODELVIEW);			// Select the modelview matrix
	glPushMatrix();					// Store the modelview matrix
	glLoadIdentity();				// Reset the modelview matrix
	glTranslated(x,y,0);				// Position the text (0,0 - Bottom left)
	glListBase(base-32+(128*set));			// Choose the font set (0 or 1)
	glCallLists(strlen(text), GL_BYTE, text);	// Write the text to the screen
	glMatrixMode(GL_PROJECTION);			// Select the projection matrix
	glPopMatrix();					// Restore the old projection matrix
	glMatrixMode(GL_MODELVIEW);			// Select the modelview matrix
	glPopMatrix();					// Restore the old projection matrix
        glDisable(GL_TEXTURE_2D);        
        glDisable(GL_BLEND);			// Enable nlending
	glEnable(GL_DEPTH_TEST);			// Enables depth testing
}
